<template>
  <!--基本信息  -->
  <div >
    	<BreakSpace :label="labels[0].title" :containerStyle="{ marginBottom: '10px' }" />
				<infoBase ref="infoBase" :formType="value.type" :formOptions="value" v-model="formData" />
			<!-- </div>
			<div class="line" id="row-02"> -->
				<BreakSpace :label="labels[1].title" :containerStyle="{ marginBottom: '10px' }" />
				<infoProduct ref="infoProduct" :formType="value.type" :formOptions="value" v-model="formData" />
			<!-- </div>
			<div class="line" id="row-03" style="min-height:780px"> -->
				<BreakSpace :label="labels[2].title" :containerStyle="{ marginBottom: '10px' }" />
				<infoPower ref="infoPower" :formType="value.type" :formOptions="value" v-model="formData" />
			<!-- </div>
			<div class="line" id="row-04"> -->
				<BreakSpace :label="labels[3].title" :containerStyle="{ marginBottom: '10px' }" />
				<infoCompany ref="infoCompany" :formType="value.type" :formOptions="value" v-model="formData" />
			<!-- </div>
			<div class="line" id="row-05"> -->
				<BreakSpace :label="labels[4].title" :containerStyle="{ marginBottom: '10px' }" />
				<infoStock ref="infoStock" :formType="value.type" :formOptions="value" v-model="formData" />
			<!-- </div>
			<div class="line" id="row-06"> -->
				<BreakSpace :label="labels[5].title" :containerStyle="{ marginBottom: '10px' }" />
				<infoFinance ref="infoFinance" :formType="value.type" :formOptions="value" v-model="formData" />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { getDetails } from '@/api/cms-api/origin/originInfo';
import { dictionary } from '@/utils/dictMixin';
import * as types from '@/api/cms-api/origin/originInfo/types';
import infoBase from '@/pages/cms-pages/origin/originInfo/dealerForm/infoBase'; //基本信息
import infoProduct from '@/pages/cms-pages/origin/originInfo/dealerForm/infoProduct'; //产品授权
import infoPower from '@/pages/cms-pages/origin/originInfo/dealerForm/infoPower'; //授权信息

import infoCompany from '@/pages/cms-pages/origin/originInfo/dealerForm/infoCompany'; //公司信息
import infoStock from '@/pages/cms-pages/origin/originInfo/dealerForm/infoStock'; //股东信息
import infoFinance from '@/pages/cms-pages/origin/originInfo/dealerForm/infoFinance'; //财务信息
import { isArray } from 'util';
import autoLoding from '@/utils/loding';//等待框
export default {
  mixins: [dictionary,autoLoding],
  props: ['data'],
  components:{
    infoBase,
    infoProduct,
    infoPower,
    infoCompany,
    infoStock,
    infoFinance
  },
  data() {
    return {
      formData: {},
      labels: [
					{ title: '基本信息', id: 'row-01' },
					{ title: '产品授权', id: 'row-02' },
					{ title: '授权信息', id: 'row-03' },
					{ title: '公司信息', id: 'row-04' },
					{ title: '股东信息', id: 'row-05' },
					{ title: '财务信息', id: 'row-06' }
      ],
      value:{
        type: 'show', //add/edit/show
        examineType:'show',//设置主表单内容为只读
        isExamine:false,//打开审核按钮和输入框
        formType:types.DEALER_INFO_FORM_STATUS_MAINTAIN_OEM,
      }
    };
  },
  mounted() {
    this.loadingVm = this.openLoding('.cover-container');
    this.getDetails(this.data.dealerAttachId)
  },
  watch:{
    'data':function(val){
      if(val){
        this.getDetails(val.dealerAttachId)
      }
    }
  },
  methods: {
    //初始化数据
    async getDetails(id){
      console.log(id,)
      let res = await getDetails(id,{});
				if(res.resultCode === 200){
					//转换附件为list<Sting>
					this.formData = this.transformAllEnclosureString(res.data);
					this.formData.inputNumber = '';
					this.formData.inputChar = '';
          console.log(this.formData,'this.formData')
					this.$nextTick(() =>{
						this.$refs.infoBase.init();
						this.$refs.infoProduct.init();
						this.$refs.infoPower.init();
						this.$refs.infoCompany.init();
						this.$refs.infoStock.init();
						this.$refs.infoFinance.init();
					});
          this.closeLoding(this.loadingVm);
				}
    },
    transformAllEnclosureString(data){
				let rdata = data;

				rdata.designFeeEnclosureList = this.transformEnclosureStringList(rdata.designFeeEnclosureList);	//设计费附件
				rdata.cashDepositEnclosureList = this.transformEnclosureStringList(rdata.cashDepositEnclosureList);	//保证金附件

				rdata.businessLicenseEnclosureList = this.transformEnclosureStringList(rdata.businessLicenseEnclosureList);	//营业执照扫描件
				rdata.legalRepresentativeEnclosureList = this.transformEnclosureStringList(rdata.legalRepresentativeEnclosureList);	//法定代表人附件
				rdata.firstPaymentEnclosureList = this.transformEnclosureStringList(rdata.firstPaymentEnclosureList);	//首笔提车款附件

				rdata.openAccountProveEnclosureList = this.transformEnclosureStringList(rdata.openAccountProveEnclosureList);	//开户证明附件

				rdata.licenceEnclosureList = this.transformEnclosureStringList(rdata.licenceEnclosureList);	//许可证附件

				//经销商形式
				let dealerAttachAuthList = [];
				if(isArray(rdata.dealerAttachAuthList)){
					rdata.dealerAttachAuthList.forEach(x => {
						dealerAttachAuthList.push(x.financeCompanyId);
					});
				}
				rdata.dealerAttachAuthList = dealerAttachAuthList;

				//车系
				let dealerAttachSeriesList = [];
				if(isArray(rdata.dealerAttachSeriesList)){
					rdata.dealerAttachSeriesList.forEach(x => {
						dealerAttachSeriesList.push(x.seriesId);
					});
				}
				rdata.dealerAttachSeriesList = dealerAttachSeriesList;

				//车型
				let dealerAttachModelList = [];
				if(isArray(rdata.dealerAttachModelList)){
					rdata.dealerAttachModelList.forEach(x => {
						dealerAttachModelList.push(x.modelId);
					});
				}
				rdata.dealerAttachModelList = dealerAttachModelList;
				return rdata;
			},
    transformEnclosureStringList(list){
				let fileUrlList = [];
				if(!isArray(list)){
					return fileUrlList;
				}
				//不再使用由IMG转FILE
				// for (let i = 0; i < list.length; i++) {
				// 	let fileUrl = list[i];
				// 	fileUrlList.push(fileUrl.fileId);
				// }
				list.forEach(x => {
					fileUrlList.push({name:x.fileName,url:x.fileId});
				});
				return fileUrlList;
			},
    formChangeHandle(val) {
      this.formValue = val;
    },
    closeDrawer(type){
      this.$emit('close');
    }
  }
};
</script>
